package cn.iocoder.yudao.module.shop.controller.admin.dayuser;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.shop.controller.admin.dayuser.vo.*;
import cn.iocoder.yudao.module.shop.dal.dataobject.dayuser.ShopDayUserDO;
import cn.iocoder.yudao.module.shop.convert.dayuser.ShopDayUserConvert;
import cn.iocoder.yudao.module.shop.service.dayuser.ShopDayUserService;

@Tag(name = "管理后台 - 艾灸师每日统计")
@RestController
@RequestMapping("/shop/day-user")
@Validated
public class ShopDayUserController {

    @Resource
    private ShopDayUserService dayUserService;

    @PostMapping("/create")
    @Operation(summary = "创建艾灸师每日统计")
    @PreAuthorize("@ss.hasPermission('shop:day-user:create')")
    public CommonResult<Long> createDayUser(@Valid @RequestBody ShopDayUserCreateReqVO createReqVO) {
        return success(dayUserService.createDayUser(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新艾灸师每日统计")
    @PreAuthorize("@ss.hasPermission('shop:day-user:update')")
    public CommonResult<Boolean> updateDayUser(@Valid @RequestBody ShopDayUserUpdateReqVO updateReqVO) {
        dayUserService.updateDayUser(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除艾灸师每日统计")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('shop:day-user:delete')")
    public CommonResult<Boolean> deleteDayUser(@RequestParam("id") Long id) {
        dayUserService.deleteDayUser(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得艾灸师每日统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('shop:day-user:query')")
    public CommonResult<ShopDayUserRespVO> getDayUser(@RequestParam("id") Long id) {
        ShopDayUserDO dayUser = dayUserService.getDayUser(id);
        return success(ShopDayUserConvert.INSTANCE.convert(dayUser));
    }

    @GetMapping("/confirm")
    @Operation(summary = "获得艾灸师每日统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('shop:day-user:update')")
    public CommonResult<Boolean> confirm(@RequestParam("id") Long id) {
        return success(dayUserService.confirm(id));
    }

    @PostMapping("/get-month")
    @Operation(summary = "获得艾灸师每日统计")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('shop:day-user:query')")
    public CommonResult<List<ShopDayUserDO>> getMonth(@Valid @RequestBody ShopDayUserMonthReqVO reqVO) {
        return success(dayUserService.getDayUserListByUserId(reqVO.getTime(), reqVO.getUserId()));
    }

    @GetMapping("/list")
    @Operation(summary = "获得艾灸师每日统计列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('shop:day-user:query')")
    public CommonResult<List<ShopDayUserRespVO>> getDayUserList(@RequestParam("ids") Collection<Long> ids) {
        List<ShopDayUserDO> list = dayUserService.getDayUserList(ids);
        return success(ShopDayUserConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得艾灸师每日统计分页")
    @PreAuthorize("@ss.hasPermission('shop:day-user:query')")
    public CommonResult<PageResult<ShopDayUserRespVO>> getDayUserPage(@Valid ShopDayUserPageReqVO pageVO) {
        PageResult<ShopDayUserDO> pageResult = dayUserService.getDayUserPage(pageVO);
        return success(ShopDayUserConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出艾灸师每日统计 Excel")
    @PreAuthorize("@ss.hasPermission('shop:day-user:export')")
    @OperateLog(type = EXPORT)
    public void exportDayUserExcel(@Valid ShopDayUserExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<ShopDayUserDO> list = dayUserService.getDayUserList(exportReqVO);
        // 导出 Excel
        List<ShopDayUserExcelVO> datas = ShopDayUserConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "艾灸师每日统计.xls", "数据", ShopDayUserExcelVO.class, datas);
    }

}
